#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>//p1706

int used[100] = { 0 };
int rept[100] = { 0 };
int n = 0;

void dfs(int k)
{
	int j = 0;
	int i = 0;

	if (k == n)
	{
		for (i = 1; i <= n; i++)
		{
			printf("%5d", used[i]);
		}
		printf("\n");
		return;
	}

	for (j = 1; j <= n; j++)
	{
		if (!rept[j])
		{
			rept[j] = 1;
			used[k + 1] = j;
			dfs(k + 1);
			rept[j] = 0;
		}
	}
}
int main()
{
	scanf("%d", &n);
	dfs(0);
	return 0;
}